<include file="../Public/_header.html" />
<div class="so_main">
  <div class="page_tit">分类管理</div>
  <div class="Toolbar_inbox">
    <a href="javascript:void(0);" class="btn_a" onclick="add(0);"><span>添加根分类</span></a>
    <php>if($parentId!=0){</php>
    <a href="javascript:void(0);" class="btn_a" onclick="add({$parentId});"><span>添加{:getCategoryNameById($parentId,'根')}子类</span></a>
    <php>}</php>
    <a href="javascript:void(0);" class="btn_a" onclick="del();"><span>删除分类</span></a>
    <a href="javascript:void(0);ui.box.load(
    											'{:U('Index://Public/showtree',array('code'=>getCategoryCode($parentId)))}'
    											,{ title:'查看{:getCategoryNameById($parentId,'根')}分类' });" class="btn_a">
    				<span>查看{:getCategoryNameById($parentId,'根')}</span>
    </a>
  </div>
  
  <div class="list">
  <table id="area_list" width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <th style="width:30px;">
        <input type="checkbox" id="checkbox_handle" onclick="table_checkAll(this)" value="0">
        <label for="checkbox"></label>
    </th>
    <th class="line_l">ID</th>
    <th class="line_l">名称</th>
    <th class="line_l">上级</th>
    
    <th class="line_l">code</th>
    <th class="line_l">order</th>
    <th class="line_l">操作</th>
  </tr>
  <volist id="vo" name="listdict">
      <tr overstyle='on' id="area_{$vo.id}">
        <td><input type="checkbox" name="checkbox" id="checkbox2" onclick="table_checkon(this)" value="{$vo.id}"></td>
        <td>{$vo.id}</td>
        
        <td><div style="float:left">
        	<a href="{:U('/Dict/index',array('parentId'=>$vo['id']))}" id="area_title_{$vo.id}">{$vo.desc}</a></div></td>
        
        <td><div style="float:left">
        	<a href="{:U('/Dict/index',array('parentId'=>$vo['pid']))}" id="area_title_{$vo.id}">{:getCategoryNameById($vo['pid'],'根')}</a></div></td>
        
        <td><div style="float:left">
        	<a href="#">{$vo.code}</a></div></td>
        
        <td><div style="float:left">
        	<a href="#">{$vo.order}</a></div></td>
        <td>
        		<a href="javascript:void(0);" onclick="add({$vo['id']});">加子类</a> 
            <a href="javascript:void(0);" onclick="edit({$vo['id']});">编辑</a> 
            <a href="javascript:void(0);" onclick="del({$vo['id']});">删除</a>  
        </td>
      </tr>
  </volist>
  </table>

  </div>
  <div class="Toolbar_inbox">
    <a href="javascript:void(0);" class="btn_a" onclick="add(0);"><span>添加根分类</span></a>
    <php>if($parentId!=0){</php>
    <a href="javascript:void(0);" class="btn_a" onclick="add({$parentId});"><span>添加{:getCategoryNameById($parentId,'根')}子类</span></a>
    <php>}</php>
    <a href="javascript:void(0);" class="btn_a" onclick="del();"><span>删除分类</span></a>
    <a href="javascript:void(0);ui.box.load(
    											'{:U('Index://Public/showtree',array('code'=>getCategoryCode($parentId)))}'
    											,{ title:'查看{:getCategoryNameById($parentId,'根')}分类' });" class="btn_a">
    				<span>查看{:getCategoryNameById($parentId,'根')}</span>
    </a>
    
  </div>
</div>

<script>

    //鼠标移动表格效果
    $(document).ready(function(){
    	table_init();
    });

    //添加分类
    function add(pid) {
        ui.box.load("{:U('/Dict/addCategory',array('pid'=>''))}"+pid, {title:'添加分类'});
    }
    
    //编辑分类
    function edit(id) {
        ui.box.load("{:U('/Dict/editCategory',array('id'=>''))}"+id, {title:'编辑分类'});
    }
    
    //删除分类
    function del(aid) {
        aid = aid ? aid : table_getChecked();
        aid = aid.toString();
        if(aid == '') return false;
				if(!confirm('确定分类删除么？其下子分类也将删除！')){
						return;
				}
        //提交删除
        $.post("{:U('/Dict/doDeleteCategory')}", {ids:aid}, function(res){
        	//alert(res);
	        if(res == '1') {
		        aid = aid.split(',');
		        $.each(aid, function(i,n){
		            $('#area_'+n).remove();
		        });
	            ui.success('删除成功');
	        }else {
	        	ui.success('删除失败');
	        }
        });
        
        
    }
    function _tmp_setselectdict(rel,txt){
    		$('#tmp_test').html('选择的id='+rel+"  分类名称:"+txt);
    }
</script>
<div id="tmp_test"></div>
<include file="../Public/_footer.html" />